﻿/*!
* File Name: forgot.js
* Created When:     2012-04-8
* Created by:       陈鹏
* Created Whys:找回密码
*/

/*Begin*/
var error_null;
var error_format;
var error_exist;
var dirs;
if (g_langID == 1033) {
	error_null = "Please enter the mailbox";
	error_format = "Mailbox format is incorrect";
	error_exist = "Mailbox does not exist";
	dirs = 'en';
	
}
else {
	error_null = '请输入邮箱';
	error_format = "邮箱格式不正确";
	error_exist = "邮箱不存在";
	dirs = 'cn';
}
$(function(){
	$(".forgotbtn input").click(function(){
		var txt=$('#txtemail').val();
	var error="";
	if (txt == "") {
		error = error_null;
	}
	else {
		if (!/^\s*([A-Za-z0-9_-]+(\.\w+)*@([\w-]+\.)+\w{2,3})\s*$/.test($.trim(txt))) {
			error = error_format;
		}
		else{
			checkEmail(txt);
		}
	}
	if (error == "") {
		sendEmail(txt);
	}
	else {
		alert(error);
	}
});
});


//验证邮箱是否存在
function checkEmail(email){
	var url = '/GateService/AjaxHttpGate.aspx?cmd=existsEmail&strEmail='+email+'&langID='+g_langID+'&random=' + new Date().toLocaleString();
	jQuery.ajax({
		url: url,
		async: false,
		type: 'get',
		success: function(data){
			if(data==0){
				error=error_exist;
				alert(error);
			}
		},
		dataType: 'text',
	});
}
//发送邮件
function sendEmail(email){
	var url = '/GateService/AjaxHttpGate.aspx?cmd=sendEmail&email=' + email + '&langID='+g_langID+'&random=' + new Date().toLocaleString();
	jQuery.ajax({
		url: url,
		async: false,
		type: 'get',
		success: function(data){
			if (data > 0) {
				$.colorbox({
					href: "/"+dirs+"/send.html",
					width: 428,
					height: 283
				});
			}
		},
		dataType: 'text',
	});
}
/*End*/